package com.prognos.web.form;

import com.prognos.domain.info.SourceDirectory;
import com.prognos.domain.selector.CssSelector;

import java.util.LinkedList;
import java.util.List;

public class SourceDirectoryForm {

    private String url;
    private Boolean fullUrl = false;
    private List<SelectorForm> selectors;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Boolean getFullUrl() {
        return fullUrl;
    }

    public void setFullUrl(Boolean fullUrl) {
        this.fullUrl = fullUrl;
    }

    public List<SelectorForm> getSelectors() {
        return selectors;
    }

    public void setSelectors(List<SelectorForm> selectors) {
        this.selectors = selectors;
    }

    public SourceDirectory ToSourceDirectory() {
        SourceDirectory sd = new SourceDirectory();
        sd.setUrl(this.url);
        sd.setFullUrl(this.getFullUrl());
        if(selectors != null && selectors.size() > 0) {
            List<CssSelector> cssSelectors = new LinkedList<>();
            for (SelectorForm selector : selectors) {
                CssSelector cssSelector = new CssSelector();
                cssSelector.setAccessor(selector.getAccessor());
                cssSelector.setSelector(selector.getValue());
                cssSelectors.add(cssSelector);
            }
            sd.setSelectors(cssSelectors);
        }
        return sd;
    }
}
